<?php
class accordion {
	public $t_content = array();
	public $t_features = array('navigation' => 'true');
	public $t_id = "accordion";

	function add_section($name){
		foreach($this->t_content as $section){
			if($section[0] == $name){
				return True;
			}
		}
		$this->t_content[] = array($name, "");
		return True;
	}

	function add_content($name, $content){
		$index = 0;
		foreach($this->t_content as $section){
			if($section[0] == $name){
				break;
			} else {
				$index = $index + 1;
			}
		}

		if ($index < count($this->t_content)) {
			$this->t_content[$index][1] .=  $content;
			return True;
		} else {
			$this->add_section($name);
			return $this->add_content($name, $content);
		}
	}
	
	function add_feature($name, $value){
		$this->t_features[$name] = $value;
	}

	function script(){
		$result = "$('#" . $this->t_id . "').accordion({ autoHeight: false";
		foreach ($this->t_features as $name => $value){
			$result .= ', "' . $name . '": ' . $value ;
		}
		$result .= "});";

		return $result;
	}

	function html(){
		$a = "";
		$a .= "\n" . '<div id="' . $this->t_id . '">' . "\n";
		$index = 1;
		foreach ($this->t_content as $content){
			$a .= "\t" . '<h3><a href="#section' . $index . '">' . $content[0] . "</a></h3>" . "\n";	
			$a .= "\t" . '<div>' . "\n";
			$a .= $content[1];
			$a .= "\t" . '</div>' . "\n";
		}
		$a .= '</div>';

		return $a;
	}

}
?>
